package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Configuration
@RestControllerAdvice
public class ExceptionCatch {

    @ExceptionHandler(Exception.class)
    public ResponseResult responseResult(Exception e) {
        log.error("ExceptionCatch ex:{}", e);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "服务器繁忙！！");
    }

    @ExceptionHandler(CustomException.class)
    public ResponseResult custException(CustomException ex) {
        log.error("CustomException ex:{}", ex);
        AppHttpCodeEnum codeEnum = ex.getAppHttpCodeEnum();
        return ResponseResult.errorResult(codeEnum);
    }
}
